<?php
/**
*
* 功能描述（用户控制器）
*
* @author suoya <jlusuoya@gmail.com>
* @version 1
*/

class CtrlUser extends CtrlBase
{
	public $paramCheck = array(
		"showlist" => array(
			"page" => array("GET", "1", "intval", "positive"),
		),
		"setlevel" => array(
			"id" => array("GET", "must", "intval", "positive"),
			"level" => array("GET", "must", "intval", "notnegative"),
			"type" => array("GET", "must", "intval", "positive"),
		),
		"setpwd" => array(
			"id" => array("GET", "must", "intval", "positive"),
		),
		"info" => array(
			"id" => array("GET", "must", "intval", "positive"),
		),
	);
	public $perm = array('user', "index.php?action=login.tologin");

	function ShowList()
	{
		$obj = $this->GetModel("user");
		$data = $obj->GetUserList($this->params['page']);
		$this->assign("listdata", $data['data']);
		$this->assign("totalCnt", $data['cnt']);
		$this->assign("pageCnt", $data['pageCnt']);
		$this->assign("curPage", $this->params['page']);
		return RT_TPL;
	}

	function SetLevel()
	{
		$obj = $this->GetModel("user");
		$id = $this->params['id'];
		$level = $this->params['level'];
		$type = $this->params['type'];
		$cnt = $obj->SetLevel($type, $id, $level);
		if($cnt == 0)
			echo "2";
		else
		{
			echo "0";
			$this->CoreLog('user_level', $id, $level, "$type");
		}
		return RT_NONE;
	}

	function SetPwd()
	{
		$obj = $this->GetModel("user");
		$id = $this->params['id'];
		$data = $obj->GetBaseInfo($id);
		if(!$data)
		{
			echo USER_NEXIST;
			return RT_NONE;
		}
		$pwd = RandStr(8);
		$cnt = $obj->SetPwd($this->params['id'], $pwd);
		echo "0";
		$this->CoreLog('user_pwd', $id, $cnt, '');
		$retmsg;
		SendMobileMsg($retmsg, array($data['mobile']), USER_PWDRST. "[$pwd]" . SAFE_NOTICE);
		return RT_NONE;
	}

	function Info()
	{
		$obj = $this->GetModel("user");
		$data = $obj->GetInfo($this->params['id']);
		if(!$data)
		{
			$this->assign("msg", "用户不存在");
			return RT_MSG;
		}
		$this->assign("data", $data);
		return RT_TPL;
	}
}

